import numpy as np
import pandas as pd

data_frame = pd.DataFrame(np.random.randint(1, 10, (3, 4)), index=list('abc'), columns=list('ABCD'))
print(data_frame)

# 获取指定列信息
print(data_frame['B'])
# 获取多个指定列信息
# FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
# print(data_frame[{'B', 'C'}])
print(data_frame[['B', 'C']])

print('*' * 50)

# 根据iloc位置索引获取指定列信息, 获取位置索引2的C列 iloc[行, 列]
print(data_frame.iloc[:, 2])
# 根据iloc位置索引获取指定的多列信息
print(data_frame.iloc[:, [0, 2]])

# 根据loc标签索引获取指定列信息, 获取位置索引C的C列 iloc[行, 列]
print(data_frame.loc[:, 'C'])
# 根据loc标签索引获取指定的多列信息
print(data_frame.loc[:, ['A', 'C']])
# 列切片, 获取B、C、D列
print(data_frame.loc[:, 'B':'D'])
